﻿import QtQuick 2.0

Image {
    id: fireBall
    width: 100
    height: 100
    source: ""

    property bool canMove: false
    property int type: 1

    property bool isAnimated: false
    property point targetPoint: Qt.point(0,0)
    property int calc: 0

    Behavior on x {
        NumberAnimation{duration: isAnimated?50:0}
    }
    Behavior on y {
        NumberAnimation{duration: isAnimated?50:0}
    }

    function ready(){

        Math.seed = window.getSeed()
        type = Math.floor(Math.random()*4)+1
        console.log("fireball.qml ready=", type)
        fireBall.x = (parent.width-width)/2
        fireBall.y = parent.height-height-100
        fireBall.source = "qrc:/img/img/ball" + String(type) + ".png"

//        isAnimated = true

    }

    function fire(){
        canMove = true
    }
    function stop(){
        canMove = false

        distroyBall()
    }

    function distroyBall(){
        fireBall.visible = false
        fireBall.destroy()
    }

    function moveToPoint(point){
        calc = 0
        canMove = false
        targetPoint = point
        isAnimated = true

        fireBall.x = targetPoint.x
        fireBall.y = targetPoint.y

        if(timer.running) return
        timer.restart()
    }

    Component.onCompleted: {
        ready()
    }

    Timer{
        id: timer
        interval: 100
        onTriggered: {
            distroyBall()
            window.handleZhanLianHou()
        }
    }
}

